import { HttpError, toSuccess, useEntityManager, useRedis } from "@sker/core";
import { AutoUser, KsDevice } from "@sker/entities";
import { useData } from "@sker/runtime";
import { z } from "zod";
import * as helper from './kwaiHelper';
/**
 * 找包
 */
export default async () => {
    const input = z.object({
        uuid: z.string()
    })
    const body = input.parse(useData())
    const data = await useEntityManager(async m => {
        const device = await m.findOne(KsDevice, { where: { uuid: body.uuid } })
        if (!device) {
            throw new HttpError(`参数有误`)
        }
        if (!device.owner) {
            throw new HttpError(`参数有误`)
        }
        const user = await m.findOne(AutoUser, { where: { mobile: device.owner } })
        if (!user) throw new HttpError(`用户不存在或已删除`)
        const userSetting = user.setting;
        if(userSetting?.status === 'stop'){
            return;
        }
        let data = await useRedis(0, async (r) => {
            return await helper.getRoomInfo(r, ['口令', '穿云箭', '快币'], body.uuid, user.setting)
        })
        return data;
    })

    return toSuccess(data)
}